package com.weidey.web.controller.tool;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.core.builder.ChatBuilder;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.weidey.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test/chat")
public class TestChatAIController {

    private static final String APIKey = "CKLsiKm6tHiQNnhc9mfOXuWW";
    private static final String SecretKey = "UYJ8HQuRwYuW6BdT74mwNnxDIK9lq5OH";
    private static Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH,APIKey, SecretKey);

    @GetMapping("/send")
    public AjaxResult sendMsg(@RequestParam("problem") String problem) {
        String result = null;
        try {
            ChatBuilder bulder = qianfan.chatCompletion().model("ERNIE-Speed-8K");
            bulder.addMessage("user",problem);//你的问题
            ChatResponse response = bulder.execute();
            result =response.getResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  AjaxResult.success(result);
    }
}
